package com.jk.smartelderlycare.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.smartelderlycare.dao.SysProcurementMapper;
import com.jk.smartelderlycare.dto.SysProcurement;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.service.SysProcurementService;
import com.jk.smartelderlycare.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysProcurementServiceImpl
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/12/5 9:57
 */
@Service
public class SysProcurementServiceImpl implements SysProcurementService {

    @Autowired
    private SysProcurementMapper sysProcurementMapper;
    /**
     * @description: 后端分页查询
     * @param: [sysProcurement, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysProcurement>
     * @author hhk
     * @date: 2024/12/5 9:34
     */
    @Override
    public PagedResponse<SysProcurement> findSysProcurementPaginationList(SysProcurement sysProcurement, Integer pageNum, Integer pageSize) {
        Page<SysProcurement> page = new Page<>(pageNum,pageSize);
       IPage<SysProcurement> procurementList =  sysProcurementMapper.findSysProcurementPaginationList(sysProcurement,page);
        return PaginationUtil.getPagedResponse(procurementList.getRecords(),pageNum,pageSize,procurementList.getTotal());
    }
    /**
     * @description: 新增
     * @param: [sysProcurement]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 16:32
     */
    @Override
    public void addSysProcurement(SysProcurement sysProcurement) {
        sysProcurement.setSystemTime(new Date());
        sysProcurementMapper.insert(sysProcurement);
        HashMap<Object, Object> map = new HashMap<>();
        if(null!=sysProcurement.getSuppIds()){
            for (Long suppId : sysProcurement.getSuppIds()) {
                map.put("documentId",sysProcurement.getDocumentId());
                map.put("suppId",suppId);
                sysProcurementMapper.addSysProcurementAndSupplier(map);
            }
        }


    }
    /**
     * @description:删除
     * @param: [documentId]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 9:40
     */
    @Override
    public void deleteSysProcurementById(Long documentId) {
        sysProcurementMapper.deleteById(documentId);
        sysProcurementMapper.deleteSysUserRoleByUserId(documentId);
    }
    /**
     * @description: 审核
     * @param: [documentId]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 9:45
     */
    @Override
    public void upStatusById(Long documentId) {
        sysProcurementMapper.upStatusById(documentId);
    }
    /**
     * @description: 未审核
     * @param: [documentId]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 9:45
     */
    @Override
    public void downStatusById(Long documentId) {
        sysProcurementMapper.downStatusById(documentId);
    }
    /**
     * @description: 根据id查询采购信息
     * @param: [documentId]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 9:45
     */
    @Override
    public void findSysProcurementById(Long documentId) {

    }
    /**
     * @description: 修改
     * @param: [sysProcurement]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 9:48
     */
    @Override
    public void updateSysProcurement(SysProcurement sysProcurement) {

    }
    /**
     * @description: 导出
     * @param: []
     * @return: com.jk.smartelderlycare.dto.SysProcurement
     * @author hhk
     * @date: 2024/12/5 9:50
     */
    @Override
    public List<SysProcurement> findSysProcurement() {
        return sysProcurementMapper.selectList(null);
    }
    /**
     * @description: 导入
     * @param: []
     * @return: com.jk.smartelderlycare.dto.SysProcurement
     * @author hhk
     * @date: 2024/12/5 9:50
     */
    @Override
    public void addProcurement(SysProcurement sysProcurement) {
        sysProcurementMapper.insert(sysProcurement);
    }
    /**
     * @description: 关闭
     * @param: [documentId]
     * @return: java.util.List<com.jk.smartelderlycare.dto.SysProcurement>
     * @author hhk
     * @date: 2024/12/5 20:39
     */
    @Override
    public void ShutdownStatusById(Long documentId) {
         sysProcurementMapper.ShutdownStatusById(documentId);
    }
}
